/**
 * Created by Administrator on 2017/3/13 0013.
 */
Hajime={
    Create:function(){
        var hajime={};
        var loader=new PIXI.loaders.Loader();
        var graphic_bg,graphic_loadingBottom,graphic_loading;
        var text_progress;
        var sp_logo;

        var bl_musicLoad=false;
        var bl_picLoad=false;

        var whole=new PIXI.DisplayObjectContainer();



        var arr_assets=[];
        arr_assets.push(
            'images/page1_1.png',
            'images/page1_2.png',
            'images/page1_3.png',
            'images/page1_4.png',
            'images/page1_5.png',
            'images/page1_6.png',
            'images/page1_7.png',
            'images/page1_8.png',
            'images/page1_9.png',
            'images/page1_10.png',
            'images/page1_11.png',
            'images/page1_12.png',
            'images/page1_13.png',
            'images/page1_14.png',
            'images/page1_15.png',
            'images/page1_16.png',
            'images/page1_17.png',
            'images/page1_18.png',
            'images/page1_21.png',
            'images/page1_22.png',
            'images/page1_23.png',
            'images/page1_24.png',
            'images/page1_99.png',
            'images/page2_1.png',
            'images/page2_2.png',
            'images/page2_3.png',
            'images/page2_4.png',
            'images/page2_5.png',
            'images/page2_6.png',
            'images/page2_7.png',
            'images/page2_8.png',
            'images/page2_9.png',
            'images/page2_10.png',
            'images/page2_11.png',
            'images/page2_12.png',
            'images/page2_13.png',
            'images/page2_14.png',
            'images/page2_15.png',
            'images/page2_16.png',
            'images/page2_17.png',
            'images/page2_18.png',
            'images/page2_19.png',
            'images/page2_21.png',
            'images/page2_22.png',
            'images/page2_23.png',
            'images/page2_24.png',
            'images/page2_25.png',
            'images/page2_26.png',
            'images/page2_27.png',
            'images/page2_28.png',
            'images/page2_29.png',
            'images/page2_30.png',
            'images/page2_31.png',
            'images/page2_32.png',
            'images/page2_33.png',
            'images/page2_34.png',
            'images/page2_35.png',
            'images/page3_1.png',
            'images/page3_2.png',
            'images/page3_3.png',
            'images/page3_4.png',
            'images/page3_5.png',
            'images/page3_6.png',
            'images/page3_7.png',
            'images/page3_8.png',
            'images/page3_9.png',
            'images/page3_10.png',
            'images/page3_11.png',
            'images/page3_12.png',
            'images/page3_13.png',
            'images/page3_14.png',
            'images/page3_15.png',
            'images/page3_16.png',
            'images/page3_17.png',
            'images/page3_18.png',
            'images/page4_1.png',
            'images/page4_2.png',
            'images/page4_3.png',
            'images/page4_4.png',
            'images/page4_5.png',
            'images/page4_6.png',
            'images/page4_7.png',
            'images/page4_8.png',
            'images/page4_9.png',
            'images/page4_10.png',
            'images/page4_11.png',
            'images/page4_12.png',
            'images/page4_13.png',
            'images/page6_1.png',
            'images/page6_2.png',
            'images/page6_3.png',
            'images/page6_4.png',
            'images/page6_5.png',
            'images/page6_6.png',
            'images/page6_7.png',
            'images/page6_8.png',
            'images/page6_9.png',
            'images/page6_10.png',
            'images/page6_11.png',
            'images/page6_12.png',
            'images/page6_13.png',
            'images/page6_14.png',
            'images/page6_15.png',
            'images/page6_16.png',
            'images/page6_17.png',
            'images/page6_18.png',
            'images/page6_19.png',
            'images/page6_20.png'
            );



        function loadProgressHandler(loader,resource){
                text_progress.text=Math.floor(loader.progress)+"%";
                graphic_loading.scale.x=loader.progress/100;
        }
        function completeHandler(){
            bl_picLoad=true;
        }
        document.addEventListener("musicLoaded",function(){
            bl_musicLoad=true;
        })


        var timer=setInterval(function(){
                if(bl_picLoad==true&&bl_musicLoad==true){
                    console.log("123");
                    AllLoaded();
                    clearTimeout(timer);
                }
        },1000);

        function AllLoaded(){
            TweenMax.to(graphic_bg,1,{alpha:0,ease:Cubic.easeInOut});
            TweenMax.to(sp_logo,0.7,{alpha:0,y:sp_logo.y-100,ease:Cubic.easeInOut});
            TweenMax.to(graphic_loading,0.7,{alpha:0,y:graphic_loading.y+100,ease:Cubic.easeInOut});
            TweenMax.to(graphic_loadingBottom,0.7,{alpha:0,y:graphic_loadingBottom.y+100,ease:Cubic.easeInOut});
            TweenMax.to(text_progress,0.7,{alpha:0,y:text_progress.y+100,ease:Cubic.easeInOut});

            console.log("HajimeCompleted");
            document.dispatchEvent(new CustomEvent("HajimeCompleted",{detail:loader.resources}));
        }


        hajime.ReturnWhole=function(){
            return whole;
        }

        hajime.initial=function(){
            graphic_bg = new PIXI.Graphics();
            graphic_bg.beginFill(0x0);
            graphic_bg.drawRect(0,0,pixiStageW,pixiStageH);
            whole.addChild(graphic_bg);

            graphic_loadingBottom=new PIXI.Graphics();
            graphic_loadingBottom.beginFill(0xcccccc);
            graphic_loadingBottom.drawRect(0,0,300,2);
            graphic_loadingBottom.x=(pixiStageW-graphic_loadingBottom.width)/2;
            graphic_loadingBottom.y=(pixiStageH/2)+40;
            whole.addChild(graphic_loadingBottom);

            graphic_loading=new PIXI.Graphics();
            graphic_loading.beginFill(0xff6600);
            graphic_loading.drawRect(0,0,300,2);
            graphic_loading.x=(pixiStageW-graphic_loading.width)/2;
            graphic_loading.y=(pixiStageH/2)+40;
            graphic_loading.scale.x=0;
            whole.addChild(graphic_loading);

            sp_logo=new PIXI.Sprite.fromImage('images/LOGO.png');
            sp_logo.anchor.set(0.5);
            sp_logo.x=pixiStageW/2;
            sp_logo.y=pixiStageH/2-50;
            whole.addChild(sp_logo);

            text_progress= new PIXI.Text('0%',{fontFamily : 'Arial', fontSize: 20, fill : 0xcccccc, align : 'center'});
            text_progress.anchor.x=0.5;
            text_progress.anchor.y=0.5;
            text_progress.x = pixiStageW/2;
            text_progress.y = pixiStageH/2+80;
            whole.addChild(text_progress);


            loader
                .add(arr_assets)
                .on("progress",loadProgressHandler)
                .load(completeHandler);
        };


        hajime.initial();





        return hajime;
    }
}